Fix #337: Enable use of TarArchive.RootPath for files under working directory#769
Open
Chris-Johnston wants to merge 3 commits intoicsharpcode:masterfrom
Open
Fix #337: Enable use of TarArchive.RootPath for files under working directory#769Chris-Johnston wants to merge 3 commits intoicsharpcode:masterfrom
Chris-Johnston wants to merge 3 commits intoicsharpcode:masterfrom
Conversation
…spect RootPath This changes the behavior of TarArchive when files are added under the CurrentDirectory. When a TarEntry is created from a file which is under the CurrentDirectory, the path is made relative to the CurrentDirectory. This behavior affects how TarArchive removes a prefix from files set by the RootPath directory. The expectation for RootPath is that a matching substring will be removed from the prefix of entries before they are added to the TarArchive. Because the TarEntry for files under CurrentDirectory are modified, RootPath will not work if it is an absolute path under CurrentDirectory. This change fixes this behavior. If RootPath is a directory under CurrentDirectory, it will apply to entres added to TarArchive. An attempt was made to implement this change without additional string manipulation. This could be done with a modified IndexOf, that enables searching for a substring of the pattern within the target substring. This may improve performance.
rizucoorg97
approved these changes
Jun 14, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change fixes #337 . I recently encountered this issue, and saw that #392 had been blocked for a while, and so I decided to take a crack at it.
This does not implement this feature using a feature flag as of writing, as suggested in the thread, but does preserve the existing behavior of adding files under the CurrentDirectory in most cases. When the RootPath is set, and is a child path of CurrentDirectory, the CurrentDirectory is removed from the RootPath, to match the behavior of TarEntry.
My main motivation for changing this behavior in TarArchive, instead of TarEntry, is so that the interface of TarEntry remains unchanged.
The existing behavior works like this: (
{workingDirectory}is not a child of/absolute/path/){workingDirectory}/temp{workingDirectory}/temp/file.txttemp/file.txt{workingDirectory}/temp/file.txttemp/file.txttemp{workingDirectory}/temp/file.txtfile.txt/absolute/path//absolute/path/file.txtfile.txt/absolute/path/file.txt/absolute/path/file.txtInstead, per #337 the behavior should be:
{workingDirectory}/temp{workingDirectory}/temp/file.txtfile.txt{workingDirectory}/temp/file.txttemp/file.txttemp{workingDirectory}/temp/file.txtfile.txt/absolute/path//absolute/path/file.txtfile.txt/absolute/path/file.txt/absolute/path/file.txtAn attempt was made to implement this change without additional string manipulation. This could be done with a modified IndexOf, that enables searching for a substring of the pattern within the target substring. This may improve performance.
I certify that I own, and have sufficient rights to contribute, all source code and related material intended to be compiled or integrated with the source code for the SharpZipLib open source product (the "Contribution"). My Contribution is licensed under the MIT License.